@extends('admin.layout.base')
@section('styles')
    <style>
        .ad-img {
            width: 200px;
            height: 180px;
            border: 1px dashed #d9d9d9;
            display: block;
            float: left;
            margin-left: 10px;
            margin-top: 10px;
        }
    </style>
@endsection
@section('content')
    <div class="panel-content" id="app" v-cloak>
        <div class="panel-body panel-info">
            <el-form :model="form" ref="form" class="form" label-width="100px">
                <div class="panel-header"> <div class="panel-title"> 投诉人信息 </div> </div>
                <div class="panel-main">
                    <el-form-item label="投诉人：" prop="user_name">
                        <el-input readonly v-model="form.user_name"></el-input>
                    </el-form-item>
                    <el-form-item label="投诉时间：" prop="created_at">
                        <el-input readonly v-model="form.created_at"></el-input>
                    </el-form-item>
                    <el-form-item label="投诉内容：" prop="content">
                        <el-input readonly type="textarea" rows="5" v-model="form.content"></el-input>
                    </el-form-item>
                    <el-form-item label="投诉图片：" prop="images">
                        <img v-for="(images,i) in form.images" :src="images" class="ad-img">
                    </el-form-item>
                </div>
                <div class="panel-header"> <div class="panel-title"> 回复信息 </div> </div>
                <div class="panel-main">
                    <el-form-item :rules="[{ max: 100, message: '回复内容的长度不能超过200个字', trigger: 'blur' }]" label="回复内容：" prop="reply_content">
                        <el-input v-if="form.isreply == 1" type="textarea" rows="5" v-model="form.reply_content"></el-input>
                        <el-input v-else readonly type="textarea" rows="5" v-model="form.reply_content"></el-input>
                    </el-form-item>
                </div>
                <el-form-item style="padding-left: 150px;margin-top: 50px">
                    <el-button v-if="form.isreply == 1" type="primary" @click="update()">保 存</el-button>
                    <el-button @click="back()" style="margin-left: 50px">返 回</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
@endsection
@section('scripts')
    <script src="{{ asset('neditor/neditor.config.js') }}" type="text/javascript"></script>
    <script src="{{ asset('neditor/neditor.all.min.js') }}" type="text/javascript"></script>
    <script src="{{ asset('neditor/neditor.service.js') }}" type="text/javascript"></script>
    <script src="{{ asset('neditor/i18n/zh-cn/zh-cn.js') }}" type="text/javascript"></script>
    <script src="{{ asset('neditor/third-party/browser-md5-file.min.js') }}" type="text/javascript"></script>
    <script src="{{ asset('neditor/third-party/jquery-1.10.2.min.js') }}" type="text/javascript"></script>
    <script>
        $(function () {
            let app = new Vue({
                el: '#app',
                data: function () {
                    return {
                        info: {!! $info !!},
                        form: {
                            id: " {{ $id }}",
                            user_id: '',
                            user_name: '',
                            content: '',
                            images: [],
                            created_at: '',
                            isreply: 0,
                            reply_content: '',
                            updated_at: '',
                            status: 2,
                        },
                    }
                },
                created() {
                    let that = this;
                    if (this.form.id > 0) {
                        this.form = {
                            id: this.info.id,
                            user_id: this.info.user_id,
                            user_name: this.info.user_name,
                            content: this.info.content,
                            images: this.info.images,
                            created_at: this.info.created_at,
                            isreply: this.info.isreply,
                            reply_content: this.info.reply_content,
                            updated_at: this.info.updated_at,
                            status: this.info.status,
                        };
                    }
                },
                methods: {
                    //返回
                    back() {
                        window.history.go(-1);
                    },
                    //更新
                    update() {
                        this.form._token = "{{csrf_token()}}";
                        this.$refs['form'].validate((valid) => {
                            if (valid) {
                                let that = this;
                                $.post("{{ route('admin.feedback.update') }}", this.form, function (res) {
                                    if (res.code) {
                                        that.$message.error(res.msg);
                                    } else {
                                        that.$message({
                                            type: 'success',
                                            duration: '1000',
                                            message: res.msg,
                                            onClose: () => {
                                                window.history.go(-1);
                                            }
                                        });
                                    }
                                }, 'JSON');
                            }
                        });
                    },
                }
            });
        })
    </script>
@endsection
